<?php $this->load->view('templates/backend/header'); ?>
<h3><?php echo $this->lang->line("voucher_list");?></h3>
<style>
    .num_cls{
        width:20%;
    }
    .btn-success,.btn-danger{
        vertical-align: top;
    }
    .notice{
        color:green;
    }
    .navbar-inverse{
        display: none;
    }
    body{
        padding-top:10px;
        padding-bottom:30px;
    }
</style>

<div class="well">
    <?php echo form_open();?>
        <div class="tab-content">	
            <div class="tab-pane active" id="main">
                <?php
                //thông tin khách hàng
                echo form_label($this->lang->line('phone'), 'phone');
                echo form_input(array('name' => 'phone', 'id' => 'phone', 'value' => ($info->phone)?$info->phone:'','required'=>'required','class'=>'num_cls','placeholder'=>$this->lang->line('phone'),'class'=>'num_cls','readonly' => 'true'));
                echo ' <span id="findCustomer"></span>';
                echo form_error('phone');
                //mã đặt chỗ
                echo form_label($this->lang->line('booking_place_code'), 'booking_place_code');
                echo form_input(array('name' => 'booking_place_code', 'id' => 'booking_place_code', 'value' => ($info->pnr)?$info->pnr:'','required'=>'required','placeholder'=>$this->lang->line('booking_place_code'),'readonly' => 'true'));
                echo ' <span id="findCustomer"></span>';
                echo form_error('booking_place_code');
                //Giá net
                echo form_label($this->lang->line('sumNet').' <span class="required">*</span>', 'net_fare');
                echo form_input(array('name' => 'net_fare', 'id' => 'net_fare', 'value' => $info->net_fare,'required'=>'required','readonly' => 'true'));
                echo form_error('net_fare');
                echo form_input(array('type' => 'hidden','name' => 'net_fare_fake', 'id' => 'net_fare_fake', 'value' => $info->net_fare));
                //Giá bán
                echo form_label($this->lang->line('sumSale').' <span class="required">*</span>', 'sale_fare');
                echo form_input(array('name' => 'sale_fare', 'id' => 'sale_fare', 'value' => $info->sale_fare,'required'=>'required','readonly' => 'true'));
                echo form_error('sale_fare');
                echo form_input(array('type' => 'hidden','name' => 'sale_fare_fake', 'id' => 'sale_fare_fake', 'value' => $info->sale_fare));
                //Số dư hiện tại
                $sodu = $this->voucher_model->getInfoContactsByParams(array('key'=>'customerID','value'=>$info->customerID));
                echo form_label($this->lang->line('surplus'), 'surplus');
                echo form_input(array('name' => 'surplus', 'id' => 'surplus', 'value' => ($sodu->surplus != NULL)?$sodu->surplus:'0','required'=>'required','readonly'=>'true'));
                echo form_error('surplus');
                echo form_input(array('type' => 'hidden','name' => 'surplus_fake', 'id' => 'surplus_fake', 'value' => ($sodu->surplus != NULL)?$sodu->surplus:'0'));
                //Giá thực
                echo form_label($this->lang->line('real_fare').' <span class="required">*</span>', 'real_fare');
                echo form_input(array('name' => 'real_fare', 'id' => 'real_fare', 'value' => $info->real_fare,'required'=>'required'));
                echo form_error('real_fare');
                echo form_input(array('type' => 'hidden','name' => 'real_fare_fake', 'id' => 'real_fare_fake', 'value' => $info->real_fare));
                
                //Số dư còn lại
                echo form_label($this->lang->line('residual'), 'residual');
                echo form_input(array('name' => 'residual', 'id' => 'residual', 'value' => ($info->residual)?$info->residual:'0'));
                echo form_error('real_fare');
                echo form_input(array('type' => 'hidden','name' => 'residual_fake', 'id' => 'residual_fake', 'value' => ($info->residual)?$info->residual:'0'));
                
                //Phương thức thanh toán
//                echo form_label($this->lang->line('payment_method').' <span class="required">*</span>', 'payment_method');
//                echo form_dropdown('payment_method', $this->voucher_model->getListPaymentMethod(),($info->payment_method)?$info->payment_method:'','id="payment_method"');
//                echo form_error('payment_method');
//                echo '<span id="payment_method_form"></span>';
                //Ghi chú booker
                echo form_label($this->lang->line('note_bk'), 'note_bk');
                echo form_textarea(array('name' => 'note_bk', 'id' => 'note_bk', 'value' => ($info->note_bk)?$info->note_bk:'','rows'=>'5','readonly' => 'true'));
                echo form_error('note_bk');
                //Ghi chú payment
                echo form_label($this->lang->line('note_pay'), 'note_pay');
                echo form_textarea(array('name' => 'note_pay', 'id' => 'note_pay', 'value' => ($info->note_pay)?$info->note_pay:'','rows'=>'5'));
                echo form_error('note_pay');
                
                echo form_input(array('type' => 'hidden','name' => 'id', 'id' => 'id', 'value' => $info->id));
                echo form_input(array('type' => 'hidden','name' => 'customerID', 'id' => 'customerID', 'value' => $info->customerID));
                ?>
            </div>
        </div>
        <div class="top-button">
                <?php echo form_button(array('id' => 'submit', 'value' => 'Update', 'name' => 'submit', 'type' => 'submit', 'content' => $this->lang->line('save'),'class' => 'btn btn-primary')); ?>
                <?php echo form_button(array('id' => 'cancelSMS','content' => $this->lang->line('close'),'class' => 'btn btn-danger','onclick'=>'closeFancy()')); ?>
        </div>
    <?php form_close();?>
    <span id="simple-msg-submit"></span>
</div>

<?php $this->load->view('templates/backend/footer'); ?>
<script src="<?php echo STATIC_URL.'backend/js/autoNumeric.js';?>"></script>
<script type="text/javascript">    
    $(document).ready(function() {
            $('#net_fare').autoNumeric('init',{aSign:' VNĐ',mDec:0, pSign:'s' });
            $("#net_fare").blur(function() {
                document.getElementById("net_fare_fake").value = UnFormatNumber($('#net_fare').val());
            });
            $('#sale_fare').autoNumeric('init',{aSign:' VNĐ',mDec:0, pSign:'s' });
            $("#sale_fare").blur(function() {
                document.getElementById("sale_fare_fake").value = UnFormatNumber($('#sale_fare').val());
            });
            $('#real_fare').autoNumeric('init',{aSign:' VNĐ',mDec:0, pSign:'s' });
            $("#real_fare").blur(function() {
                document.getElementById("real_fare_fake").value = UnFormatNumber($('#real_fare').val());
            });
            $('#surplus').autoNumeric('init',{aSign:' VNĐ',mDec:0, pSign:'s' });
            $('#residual').autoNumeric('init',{aSign:' VNĐ',mDec:0, pSign:'s' });
            $("#residual").blur(function() {
                document.getElementById("residual_fake").value = UnFormatNumber($('#residual').val());
            });
            //residual
            function FormatNumber(x) {
                if (typeof x === "undefined") {
                    return '';
                } else {
                return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") + ' VNĐ';
                }
            };
            ///,|VNĐ|\s/g
            function UnFormatNumber(x) {
                if (typeof x === "undefined") {
                    return '';
                } else {
                return x.toString().replace(/,|VNĐ|\s/g, "");
                }
            };
    });
    
    function closeFancy(){
        parent.jQuery.fancybox.close();
    }
</script>